<template>
  <div class="app-container">
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="图标" prop="pic">
        <imgUpload :limit="1" @input="upload"/>
      </el-form-item>
      <el-form-item label="服务说明" prop="serviceIllustrate">
        <el-input type="textarea" maxlength="100" show-word-limit v-model="form.serviceIllustrate" placeholder="请输入服务说明" />
      </el-form-item>
      <el-form-item label="服务类型" prop="serviceType">
        <el-select v-model="form.serviceType" placeholder="请选择服务类型">
          <el-option v-for=" (item, index) in types" :key="index" :label="item.typeName" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="enabled">
        <el-select v-model="form.enabled" placeholder="请选择状态">
          <el-option v-for=" (item, index) in status" :key="index" :label="item.value" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="服务介绍" prop="description">
        <editor v-model="form.description" height="500px" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </div>
</template>

<script>

import { STATUS } from "../../constant/constant"

import {
  listManager,
  listType,
  getManager,
  delManager,
  addManager,
  updateManager
} from "../../api/service-manager/manager";
export default {

  data() {
    return {
      types:[],
      status: STATUS,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        pic: [
          { required: true, message: "图标不能为空", trigger: "blur" }
        ],
        serviceIllustrate: [
          { required: true, message: "服务说明不能为空", trigger: "blur" }
        ],
        serviceType: [
          { required: true, message: "服务类型id不能为空", trigger: "change" }
        ],
        enabled: [
          { required: true, message: "0, 不启用; 1,启用不能为空", trigger: "blur" }
        ],
        description: [
          { required: true, message: "服务介绍不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ]
      }
    }
  },

  components: {
    imgUpload: () => import("../../components/ImageUpload/oss.vue")
  },

  mounted() {
    listType(this);
  },

  methods: {

    upload(param){
      this.form.pic = param;
      console.log("param", param);
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (!valid) {

          return;
        }

        addManager(this.form).then(response => {
          this.$modal.msgSuccess("新增成功");
          this.open = false;
          this.getList();
        });
      });
    },

    // 取消按钮
    cancel() {
      this.reset();
    },

    // 表单重置
    reset() {
      this.form = {
        id: null,
        pic: null,
        serviceIllustrate: null,
        serviceType: null,
        typeName: null,
        enabled: null,
        description: null,
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },
  }
}

</script>

<style>
textarea {
  resize: none !important;
}
</style>


